package com.cdream.basic.java8;

import java.util.Comparator;

/**
 * @author cdream
 * @date 2020-06-14
 */
public class LambdaExample {
    public static void main(String[] args) {
        // Java 8之前：
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Before Java8, too much code for too little to do");
            }
        }).start();

        //Java 8方式：
        new Thread(() -> System.out.println("In Java8, Lambda expression rocks !!")).start();


        // Java 8之前：
        Comparator<Integer> comparator = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 <= o2 ? -1 : 1;
            }
        };

        //Java 8方式：
        Comparator<Integer> comparator2 = (o1, o2) -> o1 > o2 ? 1 : -1;
    }
}
